<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Hocky extends MY_Controller {

	public $data 	= 	array();
 	public $_template = array();
	public function __construct() {
		//parent::Controller();
		parent::__construct(); //for CI 2.x users 
		$this->load->module_model('member', 'qlsv_model', 'hocky');
		$this->load->module_language('member', 'qlsv');
		$this->load->helper('text');
		$this->user = $this->access->get_user();
		$this->load->helper('url');
		$this->access->restrict();
	}
	
 
	public function index() 
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách các kỳ học';
		$data['description'] = 'Danh sách các kỳ học';
		
		$this->access->restrict();
		$this->load->library('basic_library');
		$this->load->library('pagination');
		
		$config = array();
		$config['base_url'] = base_url().'member/hocky/';
		$config['total_rows'] = $this->hocky->count_all_sinhvien();
		$config['per_page'] = 30;
		$config['uri_segment'] = 3;
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3))? $this->uri->segment(3):0;
		
		$data['allhocky'] = $this->hocky->get_all_hocky($config['per_page'], $page);
		$data['links'] = $this->pagination->create_links();		
		
		$this->_template['page']	= 'users/hocky/list';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	public function add()
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Thêm mới sinh viên';
		$data['description'] = 'Thêm mới sinh viên';

		$this->load->helper('form');
		$userid = $this->user->id;
		$lang_working = load_language_working();
		
		//here is validation form
		$this->form_validation->set_rules('tenhocky', 'lang:form_tenhocky', 'required|max_length[50]|xss_clean');
		$this->form_validation->set_rules('namhoc', 'lang:form_namhoc', 'required');
		$this->form_validation->set_rules('sotienthu', 'lang:form_sotienthu', 'required|xss_clean');
		$this->form_validation->set_rules('noidungthu','lang:form_noidungthu','required|max_length[250]');
		$this->form_validation->set_rules('tungay','lang:form_tungay','');
		$this->form_validation->set_rules('denngay','lang:form_denngay','');
		$this->form_validation->set_error_delimiters('', '<br />');

		if ($this->form_validation->run() == TRUE)
		{		
			$this->hocky->add_hocky();
			$this->session->set_flashdata('message', lang('successfully_created'));	
			redirect('member/hocky/', 'refresh');
		}	
		
		$this->_template['page']	= 'users/hocky/add';
		$this->system_library->load($this->_template['page'], $data);
	}
    
	
	public function delete($id)
	{
		$this->hocky->delete_hocky($id);
		$this->session->set_flashdata('message', lang('successfully_deleted'));
		redirect('member/hocky', 'refresh');
	}

	//Edit product
	public function edit($id)
	{
		//metadata
		$data['ItemID']		 = 'User';
		$data['title']		 = "Sửa thông tin sinh viên"; 
		$data['description'] = "Sửa thông tin sinh viên"; 
		$data['qlsv'] 	= $this->hocky->get_hocky_info($id);
		
		
		$this->form_validation->set_rules('tenhocky', 'lang:form_tenhocky', 'required|max_length[50]|xss_clean');
		$this->form_validation->set_rules('namhoc', 'lang:form_namhoc', 'required');
		$this->form_validation->set_rules('sotienthu', 'lang:form_sotienthu', 'required|xss_clean');
		$this->form_validation->set_rules('noidungthu','lang:form_noidungthu','required|max_length[250]');
		$this->form_validation->set_rules('tungay','lang:form_tungay','');
		$this->form_validation->set_rules('denngay','lang:form_denngay','');
					
		$this->form_validation->set_error_delimiters('', '<br />');
		
		if($this->form_validation->run() == TRUE)
		{
			$this->hocky->edit_hocky($id);
			$this->session->set_flashdata('message', lang('successfully_edited'));	
			redirect('member/hocky/', 'refresh');	
		}	
		$this->_template['page']	= 'users/hocky/edit';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	public function enable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->hocky->change_status_hocky($id,1);
		redirect('member/sinhvien', 'refresh');
		
	}
	public function disable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->hocky->change_status_hocky($id,0);
		redirect('member/sinhvien', 'refresh');
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/products.php */